package com.myersinfosys.protrack.poi;

import org.apache.poi.ss.usermodel.*;

public class PoiExcelCellStyles {
	private Workbook  excelWorkBook;
//	private CellStyle   headerStyle;
//	private DataFormat     dataFormat;
//	private Font           headerFont;


	public PoiExcelCellStyles(Workbook excelWorkBook)
	{
		this.excelWorkBook  = excelWorkBook;
//		headerStyle         = this.excelWorkBook.createCellStyle();
//		dataFormat = this.excelWorkBook.createDataFormat();
//		headerFont = this.excelWorkBook.createFont();
//
//
//		this.headerStyle.setFont(headerFont);
//		this.headerStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
//		this.headerStyle.setBorderBottom(CellStyle.BORDER_THIN);
//		this.headerStyle.setBorderLeft(CellStyle.BORDER_THIN);
//		this.headerStyle.setBorderRight(CellStyle.BORDER_THIN);
//		this.headerStyle.setBorderTop(CellStyle.BORDER_THIN);
//		this.headerStyle.setBottomBorderColor(IndexedColors.WHITE.getIndex());
//		this.headerStyle.setLeftBorderColor(IndexedColors.WHITE.getIndex());
//		this.headerStyle.setRightBorderColor(IndexedColors.WHITE.getIndex());
//		this.headerStyle.setTopBorderColor(IndexedColors.WHITE.getIndex());
	}
	
	public Font createCustomFontStyle(String fontName, 
								short pointSize, 
								short color, 
								Boolean bold, 
								Boolean italic,
								Boolean underline) {
		
		Font newFont = this.excelWorkBook.createFont();
		
	    newFont.setFontHeightInPoints(pointSize);
	    newFont.setColor(color);
	    newFont.setBoldweight((bold) ? Font.BOLDWEIGHT_BOLD : Font.BOLDWEIGHT_NORMAL);
	    if (fontName != null)
	    	newFont.setFontName(fontName);
	    newFont.setItalic(italic);
	    newFont.setUnderline((underline) ? Font.U_SINGLE : Font.U_NONE);
	       
	    return newFont;
	}
	
	public CellStyle createCustomCellStyle(Font cellFont, 
										   short borderTop,
										   short borderRight,
										   short borderBottom,
										   short borderLeft,
										   short borderTopColor,
										   short borderRightColor,
										   short borderBottomColor,
										   short borderLeftColor,
										   short backgroundColor,
										   short foregroundColor,
										   short fillPattern,
										   short horizAlignment,
										   short vertAlignment,
										   Boolean wrapText) {
		
		CellStyle newCellStyle = this.excelWorkBook.createCellStyle();
		
		if(cellFont != null)
			newCellStyle.setFont(cellFont);
		
//		if (border < 0) border = CellStyle.BORDER_NONE;
//		if (borderColor < 0) borderColor = IndexedColors.WHITE.getIndex();
//		if (backgroundColor < 0) backgroundColor = IndexedColors.WHITE.getIndex();
//		if (foregroundColor < 0) foregroundColor = IndexedColors.WHITE.getIndex();
//		if (fillPattern < 0) fillPattern = CellStyle.SOLID_FOREGROUND;
//		if (horizAlignment < 0) horizAlignment = CellStyle.ALIGN_CENTER;
//		if (vertAlignment < 0) vertAlignment = CellStyle.ALIGN_CENTER;
//		if (wrapText == null) wrapText = true;
		
		
		if (borderTop >= 0) newCellStyle.setBorderTop(borderTop);
		if (borderRight >= 0) newCellStyle.setBorderRight(borderRight);
		if (borderBottom >= 0) newCellStyle.setBorderBottom(borderBottom);
		if (borderLeft >= 0) newCellStyle.setBorderLeft(borderLeft);

		if (borderTopColor >= 0) newCellStyle.setTopBorderColor(borderTopColor);
		if (borderRightColor >= 0) newCellStyle.setRightBorderColor(borderRightColor);
		if (borderBottomColor >= 0) newCellStyle.setBottomBorderColor(borderBottomColor);
		if (borderLeftColor >= 0) newCellStyle.setLeftBorderColor(borderLeftColor);

		if (backgroundColor >= 0) newCellStyle.setFillBackgroundColor(backgroundColor);
		if (foregroundColor >= 0) newCellStyle.setFillForegroundColor(foregroundColor);
		if (fillPattern >= 0) newCellStyle.setFillPattern(fillPattern);
		if (horizAlignment >= 0) newCellStyle.setAlignment(horizAlignment);
		if (vertAlignment >= 0) newCellStyle.setVerticalAlignment(vertAlignment);
		if (wrapText != null) newCellStyle.setWrapText(wrapText);
		
		return newCellStyle;
	}
	
	
	
//	public CellStyle getHeaderStyle()
//	{
//		return headerStyle;
//	}
//	public DataFormat getDataFormat()
//	{
//		return dataFormat;
//	}	
//	public Font getHeaderFont()
//	{
//		return headerFont;
//	}	


}
